
<template>
  <el-form ref="form" :model="form"  label-width="100px" :rules="rules">
    <el-form-item label="所属组织：" prop="orgName">
      <el-input size="small" v-model="form.orgName"  style="width:330px;" disabled></el-input>
    </el-form-item>
    <el-form-item label="用户名：" prop="username">
      <el-input size="small" v-model="form.username"  style="width:330px;" :disabled="form.id!=''"></el-input>
    </el-form-item>
    <el-form-item label="角色：" prop="roleIds">
      <el-select v-model="form.roleIds" placeholder="" multiple  style="width:330px;">
        <el-option :label="item.name" v-for="(item,index) in roleList" :key="index" :value="item.id"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="真实姓名：" prop="name">
      <el-input disabled size="small" v-model="form.name"  style="width:330px;"></el-input>
    </el-form-item>
  </el-form>
</template>

<script>
// var validatorPhone = function (rule, value, callback) {
//   if (value === '') {
//     callback(new Error('手机号不能为空'))
//   } else if (!/^1\d{10}$/.test(value)) {
//     callback(new Error('手机号格式错误'))
//   } else {
//     callback()
//   }
// }
// function checkPhone(rule, value, callback){
//   let reg = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/
//   if (!reg.test(value)) {
//     callback(new Error('请输入正确手机号码'));
//   } else {
//     callback();
//   }
// }

let rules = {
  username: [{required: true,message:'不可为空'}],
  roleId: [{required: true,message:'不可为空'}],
}
export default {
  name: "userForm",
  mounted() {
    this.getRoleTree();
  },
  methods:{

    getRoleTree(){
      this.$api.getRolesByCriteria().then(res=>{
        this.roleList = res.data.data
      })
    },
    validate(){
      return new Promise((res,rej)=>{
        this.$refs.form.validate((v)=>{
          if(v){
            res(v)
          }else{
            rej(v)
          }
        })
      })

    },
  },
  data() {
    return {
      rules:rules,
      type:'add',
      roleList:[],
      form: {
        "email": "",
        "imgPath": "",
        "mobile": "",
        "name": "",
        "orgId": '',
        "password": "",
        "roleId": '',
        "roleIds": [],
        "username": "",
        orgName:'',
        id:''
      },
    }
  },
}
</script>

<style scoped>

</style>